# Contributor: Simon Frankenberger <simon-alpine@fraho.eu>
# Maintainer: Simon Frankenberger <simon-alpine@fraho.eu>
pkgname=java-jtreg
pkgver=5.1_p01
_pkgver=${pkgver/_p/-b}
pkgrel=2
pkgdesc="jtreg is the test harness used by the JDK test framework"
url="https://github.com/openjdk/jtreg"
arch="noarch !riscv64" # blocked by openjdk8
license="GPL-2.0"
depends="java-jtharness java-asmtools"
makedepends="openjdk8 zip" # explicitly required java 8 to compile
options="!check" # the tests require an X11 or VNC display
#subpackages="$pkgname-doc:_doc $pkgname-examples:_examples"
source="jtreg-$_pkgver.tar.bz2::https://github.com/openjdk/jtreg/archive/jtreg$_pkgver.tar.gz

jtreg-symlink-patch.txt
jtdiff-symlink-patch.txt
fix-version-number.patch
fix-build-script.patch
"
builddir="$srcdir/jtreg-jtreg$_pkgver"

build() {
	builddir="$builddir" \
	TAG_INFO="jtreg$_pkgver" \
		ash make/build-all.sh /usr/lib/jvm/default-jvm
}

package() {
	_destdir="$pkgdir/usr/share/java/jtreg"
	mkdir -p "$_destdir"
	cp -r \
		$builddir/build/images/jtreg/bin\
		$builddir/build/images/jtreg/legal \
		$builddir/build/images/jtreg/lib \
		$builddir/build/images/jtreg/COPYRIGHT \
		$builddir/build/images/jtreg/LICENSE \
		$builddir/build/images/jtreg/README \
		$builddir/build/images/jtreg/release \
		"$_destdir"

	# link to jtharness and asmtools from depends
	rm "$_destdir"/lib/asmtools.jar
	rm "$_destdir"/lib/javatest.jar
	ln -s /usr/share/java/asmtools/lib/asmtools.jar  "$_destdir"/lib/asmtools.jar
	ln -s /usr/share/java/jtharness/lib/javatest.jar "$_destdir"/lib/javatest.jar

	# patch the jtreg executable script to handle symlink from /usr/bin
	cd "$pkgdir"
	patch -p1 -i "$srcdir"/jtreg-symlink-patch.txt
	patch -p1 -i "$srcdir"/jtdiff-symlink-patch.txt

	mkdir -p "$pkgdir/usr/bin"
	ln -s /usr/share/java/jtreg/bin/jtdiff "$pkgdir"/usr/bin/jtdiff
	ln -s /usr/share/java/jtreg/bin/jtreg  "$pkgdir"/usr/bin/jtreg
}

_doc() {
	_destdir="$subpkgdir/usr/share/java/jtreg"
	mkdir -p "$_destdir"
	cp -r \
		$builddir/target/binaries/doc \
		"$_destdir"
}

sha512sums="64277f72847b6c182cd00fee39c817a1c510d7e6eef0dd01f3642d4ca661cd5215330ef4627e3557d4ba9eb212bdca3ef6539f1b5c0f72ba617c5a18063ef990  jtreg-5.1-b01.tar.bz2
136e6e58b85d05f3e97467344c95303cbd310ada7c6533a129a6e62786d5e9498a1842b75de9838b432e68d0d863058ac5aeeea2a78e98a2170b4a0c1c113083  jtreg-symlink-patch.txt
67f63317a2aaedd17e822389065ff5d86d574f4cb2e2af375856a9c7356dd048c396517372788b889db376fe4aa73c66d530938b8975d11d7714ac84e3dcd00d  jtdiff-symlink-patch.txt
769de697c43c8aeb68945f5c0f5fd42925e3cae422b732bc1c771d261ef947d1e0c865225e0384208262facad20a74f97c2905c9828215ccc24d997ee06a1356  fix-version-number.patch
a8dcf8038f8b5578a9b0580d167513933a3582f2f6d0b7230630d7abbb0e4fff1aa98f9d4e5be6a6a2fb2bbc660a5c53bd5d6ad6772bbda20c74dc3d28ba7aae  fix-build-script.patch"
